package sy10_2;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9999);

        Socket socket = serverSocket.accept();

        InputStream inputStream = socket.getInputStream();

        OutputStream outputStream = socket.getOutputStream();

        Scanner input = new Scanner(System.in);

        byte[] b = new byte[1024];
        while(true) {

            int len = inputStream.read(b);

            System.out.println(new String(b, 0, len));

            String s = input.nextLine();

            outputStream.write(("server:"+s).getBytes());
        }
    }
}

